<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "">
</@frame.head>
<script type="text/javascript">
var path="${contextPath}";
</script>
<script type="text/javascript" src="${contextPath}/resources/js/tool/ckeditor/ckeditor.js"></script>
<div class="page-container">
<form id="video" action="${contextPath}/courses/uploadFile" method="post"   enctype="multipart/form-data">
    
        <span class="btn-upload form-group">
                <input class="input-text upload-url radius" type="text"  id="uploadfile-1" readonly>
                    <a href="" class="btn btn-primary radius">
                            <i class="iconfont">&#xf0020;</i>浏览视频</a>
                <input name="file" type="file" class="input-file" >
        </span>
         <input class="btn btn-primary radius" onclick="videoSubmit()"  value="提交">
</form>
	<form action="${contextPath}/courses/course_add" method="post" class="form form-horizontal" id="jvForm" enctype="multipart/form-data" >
 <input type="hidden" name="fileName" id="fileVideoName" value="">


		<div id="file_size" style="width: 400px; border-bottom: 1px solid #C0C0C0;"></div>
		<br/>


		<div>
        <tr>
            <td width="20%">
                <span>*</span>
                上传图片(90x150尺寸):</td>
                <td width="80%">
                 注:该尺寸图片必须为90x150。
                </td>
        </tr>

                <tr>
                 <td width="20%"></td>
                    <td width="80%">
                        <img width="100" height="100" id="allUrl"/>
                        <!-- 在选择图片的时候添加事件，触发Ajax异步上传 -->
                        <input name='pic'  type="file" onchange="imgee(this)"/>
                     </td>
                </tr>
        </div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程标题：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text"  placeholder="" id="coursetitle" name="coursetitle">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程副标题：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text"  placeholder="" id="coursetitleTwo" name="coursetitleTwo">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				讲师姓名：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text"  placeholder="" id="teacher" name="teacher">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				艺术专业：</label>
			<div class="formControls col-xs-6 col-sm-6">
			<div class="radio-box">
					<select name="courseTypeOne" id="province" onchange="show(this.options[this.options.selectedIndex].value)">
						<option value="" >请选择</option>
							<#list coursesType as list>
								<option value="${list.id}">${list.coursesType}</option>
							</#list>
					</select>
					<select name="courseTypeTwo" id="pId">
					        <!-- <option value="">请选择</option>-->
					</select> 
				</div>
				<!--<input class="btn btn-success-outline radius" name="courseTypeOne" type="button" value="美术">
				<input class="btn btn-success-outline radius" name="courseTypeOne" type="button" value="色彩">
				<input class="btn btn-success-outline radius" name="courseTypeOne" type="button" value="素描">
				<input class="btn btn-success-outline radius" name="courseTypeOne" type="button" value="速写">-->
			</div>
		</div>
				<div class="mt-20 skin-minimal">
				<label class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>
					是否付费：</label>
				<div class="radio-box">
					<input type="radio" id="isPy-1" name="isPay" value="1" checked>
					<label for="radio-2">免费</label>
					<!-- <input type="radio"  id="isPay1" name="isPay" value="1" checked /> 免费 -->
				</div>

				<div class="radio-box">
					<input type=radio id="isPay-2" name="isPay" onclick="this.form.txt.style.display=''" value="2">
					<label for="radio-1">收费</label>
				</div>

				<div class="mt-20 skin-minimal">
				<label class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>
					共享模式：</label>
			<div class="radio-box">
				<input type="radio" id="radio-1" value="1" name="courseShare" checked>
				<label for="radio-1">机构专供</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="radio-2" value="2" name="courseShare">
				<label for="radio-1">平台共享</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="radio-3" value="3" name="courseShare">
				<label for="radio-1">机构内部免费,平台共享收费</label>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程简介：</label>
			<div class="formControls col-xs-6 col-sm-6">
				
				<textarea cols="80" id="content" name="courseintroduction" ></textarea> 
             <script type="text/javascript">
             window.onload = function(){ 
            	 CKEDITOR.replace('content',{filebrowserUploadUrl : path+'/ckeditor/uploader?Type=File&prodId=1111&uploadModel=product',filebrowserImageUploadUrl : path+'/ckeditor/uploader?Type=Image&prodId=${1111}&uploadModel=product',filebrowserFlashUploadUrl : path+'/ckeditor/uploader?Type=Flash&prodId=${1111}&uploadModel=product'});
             }
             </script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" onclick="submitCourses()"  value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
			</div>
	</form>
</div>
<@frame.end "default">
</@frame.end>


</html>
<script type="text/javascript">

var path="${contextPath}";
function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) {
            url = window.createObjectURL(file)
        } else if (window.URL != undefined) {
            url = window.URL.createObjectURL(file)
        } else if (window.webkitURL != undefined) {
            url = window.webkitURL.createObjectURL(file)
        }
        return url
    };

function imgee(obj) {

    // 上传设置
    var imgObj = getObjectURL(obj.files[0]);//获取图片
    $("#allUrl").attr("src", imgObj);


}
function submitCourses(){
	var content = CKEDITOR.instances.content.getData();
	 $("#content").val(content);
    $("#jvForm").ajaxSubmit({
		dataType : 'text',
        success: function(message){
        	
        		if(message == "200"){
        		
        			
                    layer.msg('上传成功!',{icon:1,time:1000},function(){
                    	parent.window.location.reload();
                    });
 				}else if(message== "505"){
 					layer.alert("只有老师机构管理员才能操作");
 				}else if(message== "500"){
 					layer.alert(message.message);
 					parent.window.location.reload();
 				}else{
 					layer.alert(message.message);
 					parent.window.location.reload();
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        },complete: function(XMLHttpRequest, textStatus) {
        	
        }
    });
}
function videoSubmit(){
    $("#video").ajaxSubmit({
		dataType : 'json',
        success: function(message){
        		if(message.code == "200"){
        			$("#fileVideoName").val(message.message);
                    layer.msg('上传成功!',{icon:1,time:1000},function(){
                    });
 				}else if(message.code == "500"){
 					layer.alert(message.message);
 				}else{
 					layer.alert(message.message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        },complete: function(XMLHttpRequest, textStatus) {
        	
        }
    });
}
var sts;
sts="<option value>请选择</option>";
$("#pId").html(sts);
function show(type) {
	
	if (type=="") {
		var sts;
		sts="<option value>请选择</option>";
		$("#pId").html(sts);
	}else{ 
		 $.ajax({
			url : path+"/courses/coursesType_Subctype?typeOne="+type,
			cache : false,
			type : 'post',
			dataType : 'json',
			error : function() {
				layer.alert("操作失败!");
			},
			success : function(message) {
				console.log(message)
        		if(message.code == "200"){
                    var arr=message.message;
                    var str;
                    for(var i=0;i<arr.length;i++){
                    	str=str+"<option value="+arr[i].id+" >"+arr[i].coursesType+"</option>";
                    }
                    $("#pId").html(str);
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
			},complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
			}
	  });
 	}
} 



</script>
